package com.example.lastwork.controller;

import com.example.lastwork.common.controller.LogicController;
import com.example.lastwork.dao.CustomerDao;
import com.example.lastwork.dto.RestDTO;
import com.example.lastwork.entity.Customer;
import com.example.lastwork.entity.Orders;
import com.example.lastwork.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "顾客服务接口")
@RestController
@RequestMapping("/CustomerController")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer, Long> {
    public CustomerController(@Autowired CustomerService service){
        super(service);
    }

    @ApiOperation("创建新订单")
    @RequestMapping(value = "/createNewOrder",method = RequestMethod.POST)
    public RestDTO<Orders> createNewOrder(@ApiParam("顾客编号") Long customerId, @ApiParam("门店编号") Long shopId){
        return RestDTO.success(getService().createNewOrder(customerId, shopId));
    }

    @ApiOperation("取消未支付的订单")
    @RequestMapping(value = "/cancelUnpaidOrder",method = RequestMethod.POST)
    public RestDTO<String> cancelUnpaidOrder(@ApiParam("顾客编号") Long customerId, @ApiParam("门店编号") Long shopId){
        return RestDTO.success(getService().cancelUnpaidOrder(customerId, shopId));
    }

    @ApiOperation("支付订单")
    @RequestMapping(value = "/payment",method = RequestMethod.POST)
    public RestDTO<String> payment(@ApiParam("订单编号") Long ordersId){
        return RestDTO.success(getService().payment(ordersId));
    }

    @ApiOperation("根据顾客编号查询订单")
    @RequestMapping(value = "/getOrdersByCustomerId",method = RequestMethod.POST)
    public RestDTO<List<Orders>> getOrdersByCustomerId(@ApiParam("顾客编号") Long customerId){
        return RestDTO.success(getService().getOrdersByCustomerId(customerId));
    }
}
